/*
 * Created on Nov 21, 2004 by Ming Chow
 *
 * RCX code for controlling a motor
 */

import josx.platform.rcx.*;
import josx.rcxcomm.*;
import java.io.*;

public class MotorControl2RCX
{
	public static void main(String[] args)
	{
		rcxReceive();
	}
	
	private static void rcxReceive()
	{
		RCXPort port;
		InputStream in;
		int cmd;
		
		try
		{
			port=new RCXPort();
			in=port.getInputStream();
			while (true)
			{
				cmd=in.read();
				setMotorAction(cmd);
			}
		}
		catch (IOException ioe) {};
	}
	
	private static void setMotorAction(int actionFlag)
	{
		switch (actionFlag)
		{
			case 1:
				Motor.C.setPower(1);
				break;
			case 2:
				Motor.C.setPower(2);
				break;
			case 3:
				Motor.C.setPower(3);
				break;
			case 4:
				Motor.C.setPower(4);
				break;
			case 5:
				Motor.C.setPower(5);
				break;
			case 6:
				Motor.C.setPower(6);
				break;
			case 7:
				Motor.C.setPower(7);
				break;
			case 8:
				Motor.C.forward();
				break;
			case 9:
				Motor.C.backward();
				break;
			default:
				Motor.C.stop();
		}
	}
}
